package Throwable;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class Error_ {
    public static void main(String[] args) throws IOException {

        /*
        * 1、空指针异常
        * */
//        int[] a = null;
//        a.toString();
        /*
         * 2、数组角标越界
         * */
//        int[] a = new int[3];
//        System.out.println(a[3]);

        /*
        * 3、字符串访问越界
        * */
//        String s = "123";
//        System.out.println(s.charAt(3));
        /*
        * 4、类型转换异常
        * Exception in thread "main" java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.String
        * */
//        Object o = new Date();
//        String  s = (String)o;

        /*
        * 5、算数异常
        * Exception in thread "main" java.lang.ArithmeticException: / by zero
        * */
//        int a= 1;
//        int b = 0;
//        System.out.println(a/b);
        /*
        * 6、数据类型转换异常
        * Exception in thread "main" java.lang.NumberFormatException: For input string: "123a"
        * */
//        String a = "123a";
//        int i = Integer.parseInt(a);

        /*
        * 7、输入类型不匹配异常
        * 输入：aaa
        * Exception in thread "main" java.util.InputMismatchException
        * */
//        Scanner input = new Scanner(System.in);
//        int i = input.nextInt();
//        System.out.println(i);

        /*
        * 1、编译时异常
        * 使用try-catch解决编译时异常
        * */
        FileInputStream fileInputStream =null;
        try{
            File file = new File("123.text");
            fileInputStream = new FileInputStream(file);
            int data = fileInputStream.read();
            while (data !=-1){
                System.out.println((char) data);
                data = fileInputStream.read();
            }

        }catch (IOException e){
            System.out.println(e.getMessage());
        }finally {
            if (fileInputStream!=null){
                fileInputStream.close();
            }

        }


    }
}
